﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EasyClassUI.entity;
using EasyClassUI.WebRequest;

namespace EasyClassUI.forms.group
{
    public partial class resourceCell : UserControl
    {
        private int groupID;
        private string fileName;
        public resourceCell(string resourceName, string resourceSize, int groupID)
        {
            InitializeComponent();
            if (resourceName.Length > 20) {
                sourceNameLabel.Text = resourceName.Substring(0, 20);
            }
            else {
                sourceNameLabel.Text = resourceName;
            }
            sourceSizeLabel.Text = resourceSize;
            this.groupID = groupID;
            this.fileName = resourceName;
            errMsgLabel.Visible = false;
        }

        private void downloadButton_Click(object sender, EventArgs e) {
            // Download file
            ResourceService resourceService = new ResourceService();
            string path = string.Empty;
            System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                path = fbd.SelectedPath;
            }
            resourceService.DownloadFileFromGroup(fileName, groupID, path + "\\" + fileName);
            errMsgLabel.Visible = true;
            errMsgLabel.Text = "Please check your folder.";
        }
    }
}
